#include "QtUI/ConnectionListComboBox.qth"
#include "QtUI/ConnectionListComboBox.moh"
#include "Storage/ConnectionConfigCollection.hpp"
#include "Storage/ConnectionConfig.hpp"

Q_DECLARE_METATYPE( const Storage::ConnectionConfig*)
Q_DECLARE_METATYPE( Storage::ConnectionConfig*)

namespace QtUI
{

ConnectionListComboBox::ConnectionListComboBox( const Storage::ConnectionConfigCollection& connColl, QWidget* pParent /*= NULL*/)
	: rConnColl_( connColl)
	, QComboBox( pParent)
{
	Storage::ConnectionConfigCollection::ConstIterator curConnI = rConnColl_.begin(),
		endConnI = rConnColl_.end();
	while( curConnI != endConnI)
	{
		QVariant data;
		data.setValue( *curConnI);
		this->addItem( QString::fromStdString((*curConnI)->name()), data);
		++curConnI;
	}
}

// ---------------------------------------------------------------------------------------------------------------------

const Storage::ConnectionConfig* ConnectionListComboBox::connConfig( int index) const
{
	QVariant data = this->itemData( index);
	return data.isNull() ? NULL : data.value<Storage::ConnectionConfig*>();
}

// ---------------------------------------------------------------------------------------------------------------------

const Storage::ConnectionConfig* ConnectionListComboBox::selectedConnConfig() const
{
	return this->connConfig( this->currentIndex());
}

} // namespace QtUI
